package com.gaogzhen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaogzhen.domain.Coin;
import com.gaogzhen.model.RRException;
import com.gaogzhen.service.CoinService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gaogzhen.mapper.AdminAddressMapper;
import com.gaogzhen.domain.AdminAddress;
import com.gaogzhen.service.AdminAddressService;
/**
* @description ${description}
* @author Administrator
* @date 2022-11-07 10:43
* @version 1.0
*/
@Service
public class AdminAddressServiceImpl extends ServiceImpl<AdminAddressMapper, AdminAddress> implements AdminAddressService{

    @Autowired
    private CoinService coinService;

    @Override
    public Page<AdminAddress> findByPage(Page<AdminAddress> page, Long coinId) {
        return page(page,
                    new LambdaQueryWrapper<AdminAddress>()
                        .eq(ObjectUtils.isNotEmpty(coinId), AdminAddress::getCoinId, coinId));
    }

    @Override
    public boolean save(AdminAddress entity) {
        Long coinId = entity.getCoinId();
        Coin coin = coinService.getById(coinId);
        if (coin == null) {
            throw new RRException("币种id错误");
        }
        entity.setCoinType(coin.getType());
        return super.save(entity);
    }
}
